package com.cctc.security.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.cctc.framework.dao.BaseDao;
import com.cctc.security.domain.User;

@Repository
public class UserDao<T extends User> extends BaseDao<Object>
{
    
    public void addUser(T t)
    {
        save(t);
    }
    
    public void updateUser(T t)
    {
        update(t);
    }
    
    public void delUser(T t)
    {
        delete(t);
    }
    
    public User findUserById(String id)
    {
        return this.getHibernateTemplate().get(User.class, id);
    }
    
    @SuppressWarnings("unchecked")
    public List<User> findAuthByUserName(final String userName)
    {
        return this.getHibernateTemplate().findByNamedQuery("listUserByAccount", new Object[] { userName });
    }
    
    
    @SuppressWarnings("unchecked")
    public List<String> getNameByAccount(final String name)
    {
        return this.getHibernateTemplate().findByNamedQuery("getNameByAccount",new Object[] {name});
    }
    
    @SuppressWarnings("unchecked")
    public List<Object> getUserAccount(StringBuffer sql)
    {
        //.addEntity("user", User.class).
        //return getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery(sql).list();
        return (List<Object>) selectSQLQuery(sql);
        //return getHibernateTemplate().find(sql);
    }
    
    
    public void add(String Sql)
    {
        notSelectSQlQuery(Sql);
    }
    
}
